package leetcode.offer_two_special.array;

/**
 * 滑动窗口
 *
 * @author mazouri
 * @create 2021-09-05 0:17
 */
public class _08_minSubArrayLen {
    public int minSubArrayLen(int target, int[] nums) {
        int left = 0;
        int sum = 0;
        int minLen = Integer.MAX_VALUE;
        for (int right = 0; right < nums.length; right++) {
            sum += nums[right];

            while (left <= right && sum >= target) {
                minLen = Math.min(minLen, right - left + 1);
                sum -= nums[left++];
            }
        }

        return minLen == Integer.MAX_VALUE ? 0 : minLen;
    }
}
